package com.nineclock.signIn.excel;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;

import com.nineclock.signIn.service.SigInService;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;


/**
 * 解析员工excel监听器
 */
@Slf4j
public class ExcelMemberListener extends AnalysisEventListener<ExcelMember> {

    private List<ExcelMember> memberList = new ArrayList<>();
    private SigInService sigInService;

    public ExcelMemberListener(SigInService sigInService) {
        this.sigInService = sigInService;
    }


    @Override
    public void invoke(ExcelMember excelMember, AnalysisContext analysisContext) {

        memberList.add(excelMember);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        log.info("解析员工excel完毕，员工数据 = " + memberList);
        sigInService.saveSignIn(memberList);
    }
}